package com.mjh.config;

import cn.hutool.jwt.JWTException;
import com.mjh.exception.ClientParameterException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author MJH
 * @date 2021-12-08
 * @Description 全局异常处理
 */
@RestControllerAdvice
public class GlobaExceptionHandler {


    /**
     * 客户端参数异常
     * @param e
     * @return
     */
    @ExceptionHandler(ClientParameterException.class)
    public ResponseEntity<String> clientParemtException(ClientParameterException e){
        return  ResponseEntity.status(420).body(e.getMessage());
    }

    /**
     * 令牌异常
     * @return
     */
    @ExceptionHandler(JWTException.class)
    public ResponseEntity<String> jwtException(){
        return ResponseEntity.status(401).body("登录已过期，请重新登录");
    }

}
